<template>
  <el-container id="app">
    <el-header height="100px">Element</el-header>
    <!-- 全屏 模式 -->
    <el-main v-if="isFullModel">
      <router-view class="router" style="height: 100%"></router-view>
    </el-main>
    <!-- 非全屏 模式 -->
    <el-container v-if="!isFullModel" class="container">
      <el-aside :width="asideWidth">
        <div class="collapse-arrow" @click="changeCollapse">
          <i class="el-icon-s-fold" style="font-size:150%" v-if="!isCollapse"></i>
          <i class="el-icon-s-unfold" style="font-size:150%" v-else></i>
        </div>
        <div v-if="isCollapse" class="el-menu-vertical" style="width: 80px;">
          <i class="el-icon-s-tools" style="font-size:150%"></i>
        </div>
        <el-menu v-if="!isCollapse" class="el-menu-vertical" text-color="#000" active-text-color="#ffd04b"
          :collapse-transition="false" default-active="0" unique-opened>
          <template v-for="router in routerData">
            <!-- 包含 children -->
            <el-submenu :index="router.path" :key="router.path" v-if="router.hasOwnProperty('children')">
              <template slot="title">
                <i class="el-icon-menu"></i><span>{{ router.name }}</span>
              </template>
              <el-menu-item v-for="child in router.children" :index="child.path" :key="child.path">
                <router-link :to="`${router.path}` + '/' + `${child.path}`">
                  <i class="el-icon-tickets"></i><span>{{ child.name }}</span>
                </router-link>
              </el-menu-item>
            </el-submenu>
            <!-- 不包含 children -->
            <el-menu-item :index="router.path" :key="router.path" v-if="!router.hasOwnProperty('children')">
              <router-link :to="`${router.path}`">
                <i class="el-icon-menu"></i><span>{{ router.name }}</span>
              </router-link>
            </el-menu-item>
          </template>
        </el-menu>
      </el-aside>

      <el-main>
        <div class="tabs">
          <tagsView></tagsView>
          <timeTitle></timeTitle>
        </div>
        <router-view class="router"></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  import tagsView from '@/common/tagsView.vue'
  import timeTitle from './common/timeTitle.vue'
  import { start } from 'qiankun'
  export default {
    components: { timeTitle, tagsView },
    data() {
      return {
        isCollapse: false,
        asideWidth: '240px',
        routerData: []

      };
    },
    computed: {
      isFullModel() {
        return this.$store.state.baseVue.isFullModel
      }

    },
    mounted() {
      console.log('App-----------mounted', this.$router.options.routes)
      console.log('cccccc', this.$store.state.baseVue.isFullModel)
      // this.$store.dispatch('baseVue/changeModel', true)
      console.log('eeeeeee', this.$store.state.baseVue.isFullModel)
      this.routerData = this.$router.options.routes.slice(1)
      if (!window.qiankunStarted) {
        window.qiankunStarted = true
        start()
      }
    },
    methods: {
      changeCollapse() {
        this.isCollapse = !this.isCollapse
        this.asideWidth = this.isCollapse ? '80px' : '240px'
      }
    }
  }
</script>

<style scoped>
  #app {
    height: 100%;
  }

  .el-header {
    background-color: #b3c0d1;
    color: aquamarine;
    font-size: 40px;
    text-align: left;
    line-height: 100px;
    /* border: 1px solid red; */
  }

  .container {
    width: 100%;
    height: calc(100% - 100px);
    background-color: #e0e0e1;
    /* border: 1px solid black; */
  }

  /* --------- el-aside --------- */
  .el-aside {
    text-align: center;
    line-height: 100px;
    overflow: hidden;
    /* border: 1px solid red; */
    padding-top: 10px;
    padding-bottom: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .collapse-arrow {
    width: 100%;
    height: 50px;
    line-height: 50px;
    background: #e1f8f4;
  }

  .el-menu-vertical {
    height: calc(100% - 60px);
    overflow-y: auto;
    overflow-x: hidden;
    background-color: #f1faf8;
    /* border: 1px solid blue; */
  }

  .el-menu-vertical span {
    display: inline-block;
    width: 120px;
    margin-left: 5px;
    /* border: 1px solid green; */
  }

  .el-main {
    padding: 10px;
    /* padding-left: 0px; */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    /* border: 1px solid blue; */
  }

  .tabs {
    width: 100%;
    height: 50px;
    background: #e1f8f4;
    display: flex;
    justify-content: space-between;
  }

  .router {
    height: calc(100% - 60px);
    background-color: #f1faf8;
    margin-top: 10px;
    color: #333;
    overflow: auto;
    border: 1px solid blue;
  }
</style>